package com.friends.utils.spring;


/**
 * 比较工具类
 * @author lihao
 */
public class CompareUtils {

    public static <T> boolean eq(Comparable<T> v1, T v2) {
        if (v1 == null || v2 == null) {
            return v1 == null && v2 == null;
        }
        final Integer eq = 0;
        return eq.equals(v1.compareTo(v2));
    }

    public static <T> boolean lt(Comparable<T> v1, T v2) {
        if (v1 == null || v2 == null) {
            throw new RuntimeException("比较的值不能为null");
        }
        final Integer result = -1;
        return result.equals(v1.compareTo(v2));
    }

    public static <T> boolean eqOrGt(Comparable<T> v1, T v2) {
        if (v1 == null || v2 == null) {
            return v1 == null && v2 == null;
        }
        int result = v1.compareTo(v2);
        return result >= 0;
    }

    public static <T> boolean gt(Comparable<T> v1, T v2) {
        if (v1 == null || v2 == null) {
            throw new RuntimeException("比较的值不能为null");
        }
        final Integer result = 1;
        return result.equals(v1.compareTo(v2));
    }


}
